﻿using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.BaseManage.Dto;
using ZR.Model.BaseManage;
using ZR.Service.BaseManage.IBaseManageService;
using ZR.Service.ProdManage.IProdManageService;
using ZR.Model.ProdManage.Dto;
using ZR.Model.ProdManage;
using System.Threading.Tasks;
using ZR.Service.ProdManage;

namespace ZR.Admin.WebApi.Controllers.AbutmentManage
{
    /// <summary>
    /// wms推送信息
    /// </summary>
    [Verify]
    [ApiExplorerSettings(GroupName = "abutment")]
    [Route("abutment/Wms")]
    public class WmsController : BaseController
    {
        /// <summary>
        /// 物料信息接口
        /// </summary>
        private readonly IBaseMaterialService _BaseMaterialService;
        /// <summary>
        /// 生产计划接口
        /// </summary>
        private readonly IProdPlanService _ProdPlanService;
        /// <summary>
        /// bom信息接口
        /// </summary>
        private readonly IProdBomService _ProdBomService;

        /// <summary>
        /// 一级装箱
        /// </summary>
        private readonly IProdOnePackService _ProdOnePackService;

        /// <summary>
        /// 二级装箱
        /// </summary>
        private readonly IProdTwoPackService _ProdTwoPackService;

        /// <summary>
        /// 三级装箱
        /// </summary>
        private readonly IProdThreePackService _ProdThreePackService;


        public WmsController(IBaseMaterialService BaseMaterialService, IProdBomService ProdBomService, IProdOnePackService ProdOnePackService, IProdTwoPackService ProdTwoPackService, IProdThreePackService ProdThreePackService)
        {
            _BaseMaterialService = BaseMaterialService;
            _ProdBomService = ProdBomService;
            _ProdOnePackService = ProdOnePackService;
            _ProdTwoPackService = ProdTwoPackService;
            _ProdThreePackService = ProdThreePackService;
        }

        /// <summary>
        /// 物料信息推送
        /// </summary>
        /// <returns></returns>
        [HttpPost("CogradientMaterial")]
        [Log(Title = "物料信息", BusinessType = BusinessType.IMPORT)]
        [AllowAnonymous]
        public async Task<IActionResult> CogradientMaterial([FromBody] List<WmsMaterialDto> list)
        {
            list = list.Where(it => !string.IsNullOrWhiteSpace(it.partCode)).Distinct().ToList();
            var response = await _BaseMaterialService.CogradientMaterial(list);

            return SUCCESS(response);
        }


        /// <summary>
        /// 生产计划推送
        /// </summary>
        /// <returns></returns>
        [HttpPost("CogradientProdPlan")]
        [Log(Title = "生产计划", BusinessType = BusinessType.IMPORT)]
        [AllowAnonymous]
        public async Task<IActionResult> CogradientProdPlan([FromBody] List<WmsPlanDto> list)
        {
            list = list.Where(it => !string.IsNullOrWhiteSpace(it.planNo)).Distinct().ToList();
            var response = await _ProdPlanService.CogradientProdPlan(list);

            return SUCCESS(response);
        }

        /// <summary>
        /// 生产bom推送
        /// </summary>
        /// <returns></returns>
        [HttpPost("CogradientProdBom")]
        [Log(Title = "生产bom", BusinessType = BusinessType.IMPORT)]
        [AllowAnonymous]
        public async Task<IActionResult> CogradientProdBom([FromBody] List<WmsBomDto> list)
        {
            list = list.Where(it => !string.IsNullOrWhiteSpace(it.itemNo)).Distinct().ToList();
            var response = await _ProdBomService.CogradientProdBom(list);

            return SUCCESS(response);
        }

        /// <summary>
        /// 一级装箱
        /// </summary>
        /// <returns></returns>
        [HttpPost("CogradientProdOnePack")]
        [Log(Title = "一级装箱", BusinessType = BusinessType.IMPORT)]
        [AllowAnonymous]
        public async Task<IActionResult> CogradientProdOnePack([FromBody] List<WmsOnePackDto> list)
        {
            var response = await _ProdOnePackService.CogradientProdOnePack(list);
            return SUCCESS(response);
        }

        /// <summary>
        /// 二级装箱
        /// </summary>
        /// <returns></returns>
        [HttpPost("CogradientProdTwoPack")]
        [Log(Title = "二级装箱", BusinessType = BusinessType.IMPORT)]
        [AllowAnonymous]
        public async Task<IActionResult> CogradientProdTwoPack([FromBody] List<WmsTwoPackDto> list)
        {
            var response = await _ProdTwoPackService.CogradientProdTwoPack(list);
            return SUCCESS(response);
        }

        /// <summary>
        /// 三级装箱
        /// </summary>
        /// <returns></returns>
        [HttpPost("CogradientProdThreePack")]
        [Log(Title = "三级装箱", BusinessType = BusinessType.IMPORT)]
        [AllowAnonymous]
        public async Task<IActionResult> CogradientProdThreePack([FromBody] List<WmsThreePackDto> list)
        {
            var response = await _ProdThreePackService.CogradientProdThreePack(list);
            return SUCCESS(response);
        }

    }
}
